package net.xinqushi.pthread.pthread;

//The Java Virtual Machine exits when the only
// threads running are all daemon threads.
// for example , GC is a daemon thread, JVM process will exit when it exits
public class DaemonThread {

    public static void main(String[] args) {

        Thread daemonThread = new Thread(() -> {
            while (true)
                System.out.println(Thread.currentThread() + " is a daemon thread , i will exit when main thread exits");
        });
        daemonThread.setDaemon(true);
        daemonThread.start();
        System.out.println(Thread.currentThread() + " will exit");
    }
}
